package at.fhj.antesk.steamvaluecalc.utils;

import java.util.List;

import at.fhj.antesk.steamvaluecalc.Game;

public class HelperUtil {

	public static double round(double value, int places){
		if (places < 0)
			throw new IllegalArgumentException();

		long factor = (long) Math.pow(10, places);
		value = value * factor;
		long tmp = Math.round(value);
		return (double) tmp / factor;
	}
	
	public static double calculateHourValueForGame(double price, double hours) {
		double hourValue = 0;

		if (hours == 0) {
			hourValue = price;
		} else {
			hourValue = price / hours;

			if (hourValue > price) {
				hourValue = price;
			}
		}
		return hourValue;
	}
	
	public static double sumUpHoursFromGameList(List<Game> gameList) {
		double totalHours = 0.0;

		for (Game game : gameList) {
			totalHours += game.getHoursOnRecord();
		}

		return totalHours;
	}
	
	public static double sumUpPricesFromGameList(List<Game> gameList) {
		double totalPrice = 0.0;

		for (Game game : gameList) {
			totalPrice += game.getPrice();
		}

		return totalPrice;
	}
	
	public static String createBoldHtmlText(String text) {
		return "<html><b>" + text + "</b></html>";
	}
}
